﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using webnew.Common;
namespace webnew.UserControls
{
    public partial class View_Navgation : WebPageBase.PageBase
    {
        private List<Model.Sys_NavigationInfo> NavList = null;
        
        protected void Page_Load(object sender, EventArgs e)
        {
           
            if (!IsPostBack)
            {
                //显示所有导航和按钮
                NavList = new BLL.Sys_Navigation().GetList();             
                CreateTree();
            }
        }

        #region  递归绑定树控件
        private void CreateTree()
        {
            foreach (Model.Sys_NavigationInfo model in NavList.Where(p => p.ParentID == "00000000-0000-0000-0000-000000000000"))
            {
                TreeNode ParentNode = new TreeNode(model.NaviName, model.Id.ToString(), "../App_Themes/Images/Icon/" + model.picsrc.ToString() + ".gif");
                ParentNode.SelectAction = TreeNodeSelectAction.Expand;
                TreeView1.Nodes.Add(ParentNode);
                GetChildNodes(ParentNode);
            }
        }

        private void GetChildNodes(TreeNode ParentNode)
        {
            foreach (Model.Sys_NavigationInfo model in NavList.Where(p => p.ParentID == ParentNode.Value))
            {
                TreeNode ChildNode = new TreeNode(model.NaviName, model.Id.ToString(), "../App_Themes/Images/Icon/" + model.picsrc.ToString() + ".gif");
                ParentNode.SelectAction = TreeNodeSelectAction.Expand;
                if (NavList.Exists(p => p.ParentID == model.Id)) GetChildNodes(ChildNode);
                ParentNode.ChildNodes.Add(ChildNode);
            }
        }
        #endregion

        
    }
}
